<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>易抽奖-首页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="index.css" type="text/css">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-lg-3 visible-xs-*"></div>
        <div class="col-lg-6" style="background-color:#DCDCDC"><br>
            <div align="center">
                <img src="./images/箭头左.svg" width="25px" height="25px" id="imgreturn">
                <input type="number" id="findnumber" class="input" placeholder="请输入抽奖邀请码"/>
                <button type="button" class="button1">搜索</button>
            </div>
            <br>
            <div align="center">
                <img src="./images/timg.png" width="200px" height="200px" style="position:center; "><br><br>
                <input type="button" class="button2" value="新建抽奖" onclick="window.open('new1.html')"><br><br>
                <input type="button" class="button2" value="我的抽奖" onclick="window.open('mylotterylist.html')"></button>
            </div>
            <br><br>
            <div class="imgleft">
                <p class="font-center">正在进行的抽奖</p>
            </div>
            <div id="holding"></div>
            <div class="col-lg-3 visible-xs-*"></div>
        </div>
    </div>
</div>
<!--页面灰色-->
<div id="returnhtml">
    <div class="theme-popover-shenhui">
        <div class="row">
            <div class="col-lg-4 visible-xs-*"></div>
            <div class="col-lg-4" style="background-color:#DCDCDC">
                <div id="search"></div>
                <div class="col-lg-4 visible-xs-*"></div>
            </div>
        </div>
    </div>

</div>
</body>

<script type="text/javascript">
    $(document).ready(function () {

                // 跳转授权
                var APPID = "63b7b59e624425d0";
                var CALLBACK = "http://f.yiban.cn/iapp133683";
// 请销假        var vq = "c21f263641f5b94c0b20f9ec5d2ad13f5662aadf66899fbcc8eb82b1541e87bdb107f75ad2866ac7fbe01e756120b81e7ced4f9cc43d5a2dff1638bea54e97045febbeeb4acaacf9ba7b81ce69a0afe548b9b44daca8bbc24cb76e672e93b8af0bcb3e7b28985f58f1730ac4eff0928dde06e7df17d89eecc9c17d9f9d24bc8d87b56b877c35bc0d8efa901e5ac330388c50db352e4577678b92b4af2e5918a1defbae73ad711c907a8b7cf2343cfb4adad311336e1ede81e40cec8374e62de9cd90cc9335fd0367e863e0e6b241fc9bf5f70392cd013b0387f3d4e23b402651"
                var vq = window.location.href.split('=')[1];
                if (vq == null)
                    window.location.href = "https://oauth.yiban.cn/code/html?client_id= " + APPID + " &redirect_uri=  " + CALLBACK + " &state=5050";
                else
                    vq = window.location.href.split('=')[1].split('&')[0];
                // 获取token
                $.post("http://yb.upc.edu.cn:8084/auth",
                    {
                        appName: "石大请销假",
                        vq: vq,
                        device: "default"
                    },
                    function (data) {
                        authtoken = data.token,
                            localStorage.setItem("testtoken", authtoken)
                        getlottery();
                    });
            var token=localStorage.getItem('testtoken');


    //绘制单个div
        function setDiv(item) {
        var div = '<div class="kuang1" data-i="'
            + item.id + ' '
            + '"><div class="picleft"><div class="picright"><p class="font-center"><p class="font-center">'
            + item.lotteryname
            + '</p></div></div></div>'
        return div
    }
    // 展示正在进行的抽奖
    function getlottery() {
        $.get("http://yb.upc.edu.cn:8084/lottery",
            {
                Authorization: authtoken
            },
            function (data) {
                var html = ''
                for (var i = 0; i < data.object.length; i++) {
                    html += setDiv(data.object[i])
                }
                document.getElementById("holding").innerHTML = html

                $('.kuang1').click(function () {

                    var kuang_id = $(this).attr('data-i')
                    window.open("lottery.html?id=" + kuang_id + "")
                })
            }
        );
    };

    //绘制搜索结果
    function setDiv2(item) {
        var div = '<div class="kuang1 "  data-i="' + item.id + '  "><div class="picleft"><div class="picright"><p class="font-center">'
            + item.lotteryname
            + '</p></div></div></div>'
        return div
    }

    //搜索框搜索
    $("button").click(function () {
        $('.theme-popover-shenhui').fadeIn(400);
        $.post("http://yb.upc.edu.cn:8084/lottery/fuzzy",
            {
                Authorization: localStorage.getItem("testtoken"),
                passcode: document.getElementById('findnumber').value
            },
            function (data) {
                if (data.length == 0) {
                    document.getElementById("no").innerHTML = "没有该抽奖，请检查你的输入"
                }
                else {
                    var html = ''
                    for (var i = 0; i < data.object.length; i++) {
                        html += setDiv2(data.object[i])
                    }
                    document.getElementById("search").innerHTML = html
                    $('.kuang1').click(function (e) {

                        var kuang_id = $(this).attr('data-i')
                        window.open("lottery.html?id=" + kuang_id + "")
                    })
                }
            })
    })

    //展示搜索结果后点箭头返回主页
    $("img#imgreturn").click(function () {
        $('.theme-popover-shenhui').fadeOut(200);
    })

    });
</script>
</html>
